package com.zhou.zhxy.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhou.zhxy.pojo.Grade;
import com.zhou.zhxy.service.GradeService;
import com.zhou.zhxy.util.Result;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * RestController  异步交互使用
 */

@RestController
@RequestMapping("/sms/gradeController")
public class GradeController {

    @Autowired
    private GradeService gradeService;

    @GetMapping("/getGrades")
    public Result getGrades(){
        List<Grade> list = gradeService.getGradeList();
        return Result.ok(list);
    }

    @GetMapping("/getGrades/{pageNo}/{pageSize}")
    public Result getGrades(
            @ApiParam("页码") @PathVariable("pageNo") Integer pageNo,
            @ApiParam("页数") @PathVariable("pageSize") Integer pageSize,
            @ApiParam("分页查询") Grade grade
    ){
        Page<Grade> page = new Page<>(pageNo,pageSize);
        IPage<Grade> iPage = gradeService.getGradeLists(page,grade);
        return Result.ok(iPage);
    }
}
